package com.base.cn.platform.os.service.op.coupon;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.dao.op.coupon.OpUserCourseOpenCodeDao;
import com.base.cn.platform.os.entity.op.coupon.OpUserCourseOpenCode;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 用户参加免费直播赠送优惠券记录Biz
 *
 * @author s.li
 * @create 2018-10-03-11:11
 */
@Service
public class OpUserCourseOpenCodeBiz extends BaseBiz<OpUserCourseOpenCode,OpUserCourseOpenCodeDao> {

    /**
     * 获取用户的免费直播程赠送优惠券记录
     * @param userId 用户ID
     * @param openCourseId 免费直播ID
     * @return List<OpUserCourseOpenCode>
     */
    public List<OpUserCourseOpenCode> findUserCourseOpenCodeList(BigDecimal userId,BigDecimal openCourseId){
        List<OpUserCourseOpenCode> userCourseOpenCodeList = this.find(" userId="+userId+" and openCourseId="+openCourseId,null,null);
        return userCourseOpenCodeList;
    }

    /**
     * 判断用户是否赠送指定免费直播的优惠券
     * @param userId 用户ID
     * @param openCourseId　免费直播ID
     * @return true赠送过，false未赠送过
     */
    public boolean isGiveUserCourseOpenCode(BigDecimal userId,BigDecimal openCourseId){
        List<OpUserCourseOpenCode> list = this.findUserCourseOpenCodeList(userId,openCourseId);
        if(ObjectUtils.isNotEmpty(list)){
            return true;
        }
        return false;
    }
}
